package init

import (
	"RESTfulAPI/basic/config"
	__ "RESTfulAPI/basic/proto"
	"RESTfulAPI/utils"
	"flag"
	"github.com/google/uuid"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
)

func init() {
	InitGroup()
}
func InitGroup() {
	client := utils.Consul{
		ID:      uuid.NewString(),
		Name:    "user",
		Address: "1.94.61.178:8500",
		Port:    8511,
		Tags:    make([]string, 0),
	}
	consulClient, err := utils.NewConsulClient(client.Address)
	if err != nil {
		log.Fatal(err)
	}
	err = consulClient.Register(&client)
	if err != nil {
		log.Fatal(err)
	}

	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	config.UserClient = __.NewUserClient(conn)
}
